<template>

    <div>

        <van-nav-bar title="收货地址" left-text="返回" left-arrow />
        <van-radio-group v-model="radio">

            <van-radio v-for="(item) in Address" :key="item.addressId" :name="item.addressId">

                <p>{{item.addressName}}  <span>{{item.addressPhone}}</span> </p>
                <p class="dz">{{item.addressContent}}</p>
                <span v-if="item.isDefault==1" class="moren">默认</span>
                <van-button v-if="item.isDefault==0" @click="mz(item.addressId)" type="primary" size="mini">设为默认</van-button>

            </van-radio>

        </van-radio-group>
        <van-button type="primary" class="tjdz" color="linear-gradient(to right, #ff6034, #ee0a24)" size="large">添加地址</van-button>

    </div>

</template>

<script>
    export default {
        name: "addresslist",
        data() {
            return {
                radio: 1,
                edit:{},
                Address:[]
            };
        },
        methods: {
            mz(id){
                //  /address/findEditAddress
                let sess = JSON.parse(sessionStorage.getItem("user"))
                this.$axios.post('/api/address/findEditAddress?addressId='+id).then((res)=>{
                    this.edit=res.data.data
                    this.edit.isDefault=1
                    this.$axios.post('/api/address/edit',this.edit).then((res)=>{
                        this.$axios.post('/api/address/list?userId='+sess.userId).then((res)=>{
                            this.Address=res.data.data
                            console.log(this.Address)
                        })
                    })

                }).catch((err)=>{console.log("失败")})



            }






        },

        created(){
            let sess = JSON.parse(sessionStorage.getItem("user"))
            //全部
            this.$axios.post('/api/address/list?userId='+sess.userId).then((res)=>{
                this.Address=res.data.data
                console.log(this.Address)
            }).catch((err)=>{console.log("失败")})
        }
    }
</script>

<style scoped>
    *{
        margin: 0px;
        padding: 0px;
    }
    .dz,.moren{
        font-size: 13px;
    }

    .van-radio{
        height: 60px;
        background-color: #F7F8FA;
        margin-top: 15px;
        margin-left: 10px;
        margin-right: 10px;


    }
    .tjdz{
        position: absolute;
        bottom: 10px;
        margin: 10px;

    }
    .moren{
        color: red;
    }

</style>